home *** CD-ROM | disk | FTP | other *** search
- unit ExecWait;
- interface
-
- function WinExecAndWait(Path: Pchar; Visibility: Word): Word;
- { Use this code to launch a second program from inside a Turbo
- Pascal for Windows program. It accepts the same parameters as
- WinExec, but will loop continuously until the launched program
- has terminated. This code exists because it is sometimes
- necessary to launch a second program without executing any more
- code in your program. If you did not take this approach, then
- both programs would be executing simultaneously via Windows
- multitasking abilities.
- }
-
- implementation
- uses WinTypes,
- WinProcs,
- Messages;
-
- function WinExecAndWait(Path: Pchar; Visibility: Word): Word;
- var InstanceID : THandle;
- Msg : TMSg;
- begin
- InstanceID := WinExec(Path,Visibility);
- if InstanceID < 32 then { a value less than 32 indicates an Exec error }
- WinExecAndWait := InstanceID
- else
- repeat
- while PeekMessage(Msg,0,0,0,PM_REMOVE) do
- begin
- if Msg.Message = WM_QUIT then halt(Msg.wParam);
- TranslateMessage(Msg);
- DispatchMessage(Msg);
- end;
- until GetModuleUsage(InstanceID) = 0;
- end {WinExecAndWait};
- end.
-